﻿CREATE PROCEDURE [dbo].[Bookmark_Save]
	@textId BIGINT,
	@userId	UNIQUEIDENTIFIER,
	@title NVARCHAR(256)
AS
BEGIN
	DECLARE @bookmarkId BIGINT

	SELECT @bookmarkId = [BookmarkId]
	FROM [dbo].[mark_Bookmark]
	WHERE [TextId] = @textId AND [UserId] = @userId


	IF @bookmarkId IS NULL
	BEGIN
		INSERT INTO [dbo].[mark_Bookmark]
								([TextId]
								,[Title]
								,[UserId])
					VALUES
								(@textId			--<TextId, bigint,>
								,@title			--<Title, nvarchar(256),>
								,@userId			--<UserId, uniqueidentifier,>
								)

		SET @bookmarkId = SCOPE_IDENTITY()
	END

	SELECT @bookmarkId AS [BookmarkId]
END